<template>
    <div>
        <el-upload class="upload-demo" :action='urlUpdate' :on-change="handleChange" :on-remove="handleRemove"
            :on-success="handleSuccess" :on-error="handleError" :file-list="fileList" :on-preview="handlePreview" :headers="token" disabled>
            <!-- <el-button size="mini" type="primary" disabled>点击上传</el-button> -->
        </el-upload>
    </div>
</template>
  
<script>
import { treeClassTranslate } from "../../../utils/treeDataTranslate.js";
export default {
    emits: ["refreshDataList"],
    props:{
        fileLists:Array
    },
    data() {
        return {
            urlUpdate: '',//文件上传路径
            token: {
                token: ''
            },
            formLabelWidth: "120px",
            fileList: [],//规格书
            // url: process.env.VUE_APP_BASE_API,
        };
    },
    created() {
        this.urlUpdate = process.env.VUE_APP_BASE_API + '/file/uploadFileInterface'
        this.token.token = sessionStorage.getItem("Token");
        console.log(this.token)
        console.log(this.fileLists)
    },
    watch:{
        fileLists:{
				handler(newVal) {
					this.fileList=newVal
				},
				deep: true
			}
    },
    methods: {
        async init(id, val) {

        },
        //上传文件
        handleChange(file, fileList) {
            this.fileList = fileList;
            
        },
        // 点击文件下载
        handlePreview(file) { this.fileDown(file); },
        handleRemove(file, fileList){},
        //删除文件
        async picRemove(picarr, picid, data) {
            await this.Sevice({
                url: '/file/deleteFileInterface',
                method: 'post',
                data: data,
                headers: { 'Content-Type': 'multipart/form-data' }
            }).then((res) => {
                if (res.code != 200) {
                } else {
                    // this.$message({
                    // 	message: res.msg,
                    // 	type: 'success',
                    // 	duration: 1500
                    // })
                }
            })
            for (let i = 0; i < picarr.length; i++) {
                if (picarr[i].response.map.id === picid) {
                    picarr.splice(i, 1);
                }
            }
            return picarr;
        },
        //附件上传成功回调
        handleSuccess(response, file, fileList) {
            console.log(response, file, fileList)
            if(response.code==200){
                this.$emit('uploadFile',this.fileList)
            }else{
                for(let i=0;i<fileList.length;i++){
                    if(fileList[i].uid==file.uid){
                        fileList.splice(i, 1);
                    }
                }
                this.$message({ message: response.msg, type: 'error', duration: 1000 })
            }
         },
         handleError(err, file, fileList){
            console.log(err)
            // this.$message({ message: response.msg, type: 'error', duration: 1000 })
         }
    },
};
</script>
  
<style scoped>
</style>
  